//方法1---arr[6]为undefined
// function fn(arr1, arr2) {
//   let arr = [];
//   for (let i = 0; i < Math.max(arr1.length,arr2.length); i++){
//     arr.push(arr1[i]);
//     arr.push(arr2[i]);
//   }
//   return console.log(arr);
// }
//
// fn([1,2,3], [4,5,6,7]);

//方法2---成功
function fn(arr1, arr2) {
  let arr = [];
  for (let i = 0; i < Math.min(arr1.length,arr2.length); i++){
    arr.push(arr1[i]);
    arr.push(arr2[i]);
  }
  if(arr1.length < arr2.length){
    for (let i = arr1.length; i < arr2.length; i++){
      arr.push(arr2[i]);
    }
  }
  else{
    for (let i = arr2.length; i < arr1.length; i++){
      arr.push(arr1[i]);
    }
  }
  return console.log(arr);
}

fn([1,2,3], [4,5,6,7,8]);
